Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: courier templates fs support #2164

Merged
merged 6 commits into from
Jan 20, 2022
Merged

Conversation

Benehiko
Copy link
Contributor

Adds embed.FS support to the templates.

Related issue(s)

Checklist

  • I have read the contributing guidelines.
  • I have referenced an issue containing the design document if my change
    introduces a new feature.
  • I am following the
    contributing code guidelines.
  • I have read the security policy.
  • I confirm that this pull request does not address a security
    vulnerability. If this pull request addresses a security. vulnerability, I
    confirm that I got green light (please contact
    [email protected]) from the maintainers to push
    the changes.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added or changed the documentation.

Further Comments

var b bytes.Buffer
if err := t.Execute(&b, model); err != nil {
return "", err
}
return b.String(), nil
}

func LoadHTMLTemplate(osdir, name, pattern string, model interface{}) (string, error) {
t, err := loadTemplate(osdir, name, pattern, true)
func LoadHTMLTemplate(osdir, name, pattern string, model interface{}, fs ...embed.FS) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we will only use the first embedFS argument. So maybe just make this a regular arg?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but then it won't be optional anymore. we will then require the current functions to pass a nil i guess

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three options:

  1. nil is acceptable (okayish)
  2. just pass the FS in the caller (preferable)
  3. if more options are anticipated add an options struct (least preferable because extra work that can easily be avoided, not many options planned in the future)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, okay, I will implement option 2.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Benehiko :)

@Benehiko
Copy link
Contributor Author

Benehiko commented Jan 20, 2022

Just to make sure I'm not adding any regressions. What is the purpose of the pattern parameter in this case? To me, it seems strange since if name doesn't match, pattern doesn't matter. So we know the file exists through its name. But then we use the pattern (if it exists) to call up the file instead.

https://github.com/ory/kratos/blob/master/courier/template/load_template.go#L80-L87

I see it was added through 54b97b4

Okay got it now. Will keep it intact.

@codecov
Copy link

codecov bot commented Jan 20, 2022

Codecov Report

Merging #2164 (eb6dd92) into master (db14cd5) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2164      +/-   ##
==========================================
- Coverage   75.24%   75.22%   -0.03%     
==========================================
  Files         294      294              
  Lines       15618    15618              
==========================================
- Hits        11752    11748       -4     
- Misses       3032     3035       +3     
- Partials      834      835       +1     
Impacted Files Coverage Δ
courier/template/load_template.go 66.66% <100.00%> (ø)
courier/template/recovery_invalid.go 100.00% <100.00%> (ø)
courier/template/recovery_valid.go 100.00% <100.00%> (ø)
courier/template/stub.go 100.00% <100.00%> (ø)
courier/template/verification_invalid.go 100.00% <100.00%> (ø)
courier/template/verification_valid.go 100.00% <100.00%> (ø)
session/test/persistence.go 98.61% <0.00%> (-1.39%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db14cd5...eb6dd92. Read the comment docs.

@aeneasr
Copy link
Member

aeneasr commented Jan 20, 2022

Great stuff, thank you @Benehiko !

@aeneasr aeneasr merged commit 13689a7 into ory:master Jan 20, 2022
@vinckr vinckr mentioned this pull request Mar 18, 2022
peturgeorgievv pushed a commit to senteca/kratos-fork that referenced this pull request Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants